Package com.graphics

Source Code of com.graphics.Camera

package com.graphics;

import com.fish.Fish;
import com.fish.Route;
import com.fish.State;
import com.math.Quat;
import com.math.Vector;

/**
* @author Dror
*
* email: gumjum.o.o@gmail.com
*
*/


public class Camera extends Box{

  Vector e = new Vector(0,0,-3000f);
  Vector tmp = new Vector(),foo = new Vector();

  Vector center = new Vector();
  Vector folCamDis = new Vector(0f,20f,-100f);
  Quat folCamRot = new Quat();

  Vector eyesDist = new Vector(0, 10, -10);
 
  float xz = 0, xy = 0;
  float vxz = 0, vxy = 0;
  float linVel = 0;
 
  enum CamMode {stand,following,eyes};

  CamMode cm = CamMode.stand;

  public Fish followedFish;
  float rad = 500f;

  /**
   * Constructor
   */
  public Camera(Vector pos,Quat rot) {//Vector rot
    super(new Vector(1,1,2), pos, rot,int2color(0));
 

  public void rotate(float dx,float dy,float dz){

    Quat tmpQ = new Quat();


    tmpQ.fromEulerAngles(dx,dy,dz);

    //    System.out.println(tmpQ + " --- " + r);

    r.multiply(tmpQ);

    //    System.out.println(r);
  }

  public void move(float dz){
    rad += dz;
    rotate(0,0,0);
  }

  public void reset(){
    p = new Vector(0,0,-500);
    r = new Quat();
    center.set(0,0,0);
    rad = 500f;
    xy = 0; xz = 0;
    cm = CamMode.stand;
    e.set(0,0,-3000);
  }

  public Vector getRay(){
    Vector ray = new Vector(0,0,1);
    //    r.rotateVector(ray);
    r.rotate(ray);
    return ray;   
  }

  public int getType() {
    // TODO Auto-generated method stub
    return 9;
  }


  public void changeAngles(float dx,float dy){
    this.xy += dy*0.0174532925f;
    this.xz += dx*0.0174532925f;
  }

  public void changeRad(float dr){
    this.rad += dr;
  }


  public void step() {

    rad += linVel;
   
    if(cm == CamMode.eyes && followedFish != null){
     
      this.p.set(eyesDist);
     
     
      r.set(0,0,0,0);
     
      for(State s:followedFish.route.backward){
        r.setAdd(s.r);
      }
     
      r.x /= Route.BACKWARD_STATE_NUM;
      r.y /= Route.BACKWARD_STATE_NUM;
      r.z /= Route.BACKWARD_STATE_NUM;
      r.w /= Route.BACKWARD_STATE_NUM;
     
      r.normalize();
 
      this.p.transformation(r,followedFish.p);
     
    }
    else{
     
      xz += vxz;
      xy += vxy;
     
      if(cm == CamMode.following && followedFish != null){
        this.center.set(this.followedFish.p);
      }

      p.x = center.x - (float)Math.sin(xz)*rad;
      p.z = center.z - (float)Math.cos(xz)*rad;
      p.y = center.y + (float)Math.sin(xy)*rad;

      //    System.out.println(p+"---"+center);
      //    System.out.println(center.sub(p).length());
      r.fromTo(p,new Vector(center.x,center.y,center.z-rad));
      r.invert();
    }
  }

  public void fromEyes(Fish selectedFish) {
    followedFish = selectedFish;
    cm = CamMode.eyes;
    e.set(0,0,-150);
  }

  public void follow(Fish selectedFish) {
    followedFish = selectedFish;
    cm = CamMode.following;
    e.set(0,0,-3000);
  }

  public void setVel(float f, float g) {
    vxz = f*0.0174532925f;
    vxy = g*0.0174532925f;
  }

  public void setLinVel(float v) {
    linVel = v;   
  }

}
TOP

Related Classes of com.graphics.Camera

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.